import { h } from 'vue';

import BasicLayout from '@/layouts/basic-layout';
import settings from './modules/settings';

/**
 * 在主框架内显示
 */

const frameIn = [
    {
        path: '/',
        redirect: {
            name: 'spokensman'
        },
        component: BasicLayout,
        children: [            
            // 刷新页面 必须保留
            {
                path: 'refresh',
                name: 'refresh',
                hidden: true,
                component: {
                    beforeRouteEnter (to, from, next) {
                        next(instance => instance.$router.replace(from.fullPath));
                    },
                    render: () => h()
                }
            },
            // 页面重定向 必须保留
            {
                path: 'redirect/:route*',
                name: 'redirect',
                hidden: true,
                component: {
                    beforeRouteEnter (to, from, next) {
                        next(instance => instance.$router.replace(JSON.parse(from.params.route)));
                    },
                    render: () => h()
                }
            },
            
            {
                path:'consume',
                name:'consume',
                meta:{
                    title:'消费列表',
                    auth:true,
                    keepAlive:true                    
                },
                component: ()=> import('@/pages/consume')
            },
            {
                path:'spokensman',
                name:'spokensman',
                meta:{
                    title:'代言人',
                    auth:true,
                    keepAlive:true         
                },
                component: ()=> import('@/pages/spokensman')
            },{
                path:'client',
                name:'client',
                meta:{
                    title:'客户列表',
                    auth:true,
                    keepAlive:true         
                },
                component: ()=> import('@/pages/client')
            },{
                path:'appointment',
                name:'appointment',
                meta:{
                    title:'预约列表',
                    auth:true,
                    keepAlive:true         
                },
                component: ()=> import('@/pages/appointment')
            },{
                path:'consume',
                name:'consume',
                meta:{
                    title:'消费列表',
                    auth:true,
                    keepAlive:true         
                },
                component: ()=> import('@/pages/consume')
            },{
                path:'suggestion',
                name:'suggestion',
                meta:{
                    title:'客户意见',
                    auth:true,
                    keepAlive:true         
                },
                component: ()=> import('@/pages/suggestion')
            }
        ]
    },
    settings,
    {
        path:'/development',
        name:'development',
        meta: {
            title:'开发设置',
            auth:true,
            keepAlive:true         
        },
        redirect: {
            name:`menu`
        },
        component:BasicLayout,
        children:[
            {
                path: '/development/menu',
                name: `menu`,
                meta: {
                    auth:true,
                    title: '菜单',
                    keepAlive:true         
                },
                component: () => {
                    return import ('@/pages/development/menu'); 
                },
            },
            {
                path: '/development/action',
                name: `action`,
                meta: {
                    auth:true,
                    title: '动作',
                    keepAlive:true         
                },
                component: () => {
                    return import ('@/pages/development/action'); 
                },
            },
        ]
    }
    
    
];

/**
 * 在主框架之外显示
 */

const frameOut = [
    // 登录
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '$t:page.login.title'
        },
        component: () => import('@/pages/account/login')
    },
    // 注册
    {
        path: '/register',
        name: 'register',
        meta: {
            title: '$t:page.register.title'
        },
        component: () => import('@/pages/account/register')
    },
    // 注册结果
    {
        path: '/register/result',
        name: 'register-result',
        meta: {
            auth: true,
            title: '注册结果'
        },
        component: () => import('@/pages/account/register/result')
    }
];

/**
 * 错误页面
 */

const errorPage = [
    {
        path: '/403',
        name: '403',
        meta: {
            title: '403'
        },
        component: () => import('@/pages/system/error/403')
    },
    {
        path: '/500',
        name: '500',
        meta: {
            title: '500'
        },
        component: () => import('@/pages/system/error/500')
    },
    {
        path: '/:pathMatch(.*)',
        name: '404',
        meta: {
            title: '404'
        },
        component: () => import('@/pages/system/error/404')
    }
];

// 导出需要显示菜单的
export const frameInRoutes = frameIn;

// 重新组织后导出
export default [
    ...frameIn,
    ...frameOut,
    ...errorPage
];
